using ASP;
using HoWave.Common;
using HoWave.Data;
using HoWave.Data.Bll;
using HoWave.Web;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class _setSendAndPayment : Shop, IRequiresSessionState
{
	private Shop_Product _shop_product = null;
	private CreateOrder _creatOrder = null;
	private Shop_Shop _shop_shop = null;
	private string _shopcartID = string.Empty;
	protected UserControls_cmpy_Top Top1;
	protected ScriptManager ScriptManager1;
	protected Label Label2;
	protected Repeater Repeater1;
	protected HtmlGenericControl payment;
	protected Button btn_back;
	protected Button btn_next;
	protected UserControls_CMYP_Foot Foot1;
	protected HtmlForm form1;
	protected HtmlGenericControl Html1;
	protected Shop_Product shop_product
	{
		get
		{
			Shop_Product shop_product;
			if (this._shop_product == null)
			{
				this._shop_product = new Shop_Product(this.conn);
				shop_product = this._shop_product;
			}
			else
			{
				shop_product = this._shop_product;
			}
			return shop_product;
		}
	}
	protected CreateOrder creatOrder
	{
		get
		{
			CreateOrder creatOrder;
			if (this._creatOrder == null)
			{
				this._creatOrder = new CreateOrder(this.conn);
				creatOrder = this._creatOrder;
			}
			else
			{
				creatOrder = this._creatOrder;
			}
			return creatOrder;
		}
	}
	protected Shop_Shop shop_shop
	{
		get
		{
			Shop_Shop shop_shop;
			if (this._shop_shop == null)
			{
				this._shop_shop = new Shop_Shop(this.conn);
				shop_shop = this._shop_shop;
			}
			else
			{
				shop_shop = this._shop_shop;
			}
			return shop_shop;
		}
	}
	protected string shopcartID
	{
		get
		{
			this._shopcartID = Fetch.Get("shopcartID");
			return this._shopcartID;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_PreInit(object sender, EventArgs e)
	{
		if (!base.user.CheckUserLogin())
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Common/NotLogin", new string[0]), "Passport/Login.aspx?ComeUrl=" + this.InstallDir + "setSendAndPayment.aspx");
		}
		try
		{
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message.ToString());
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		base.ShowCityArea();
		if (!base.IsPostBack)
		{
			try
			{
				this.loadinfo();
			}
			catch
			{
				MessageBox.ShowAndRedirect(this, "请检查购物车中有无商品！", "ShoppingCart.aspx");
			}
		}
	}
	private void loadinfo()
	{
		DataSet dataSet = this.getDataSet();
		if (dataSet != null)
		{
			this.Repeater1.DataSource = dataSet;
			this.Repeater1.DataBind();
			DataTable dataTable = dataSet.Tables[0];
			this.Label2.Text = dataTable.Rows.Count.ToString();
			foreach (DataRow dataRow in dataTable.Rows)
			{
				DataTable shopByShopID = this.shop_shop.GetShopByShopID((int)dataRow["shopID"]);
			}
		}
		else
		{
			MessageBox.ShowAndRedirect(this, "请检查购物车中有无商品！", "ShoppingCart.aspx");
		}
	}
	private DataSet getDataSet()
	{
		DataSet dataSet = null;
		string text = "";
		string text2 = "";
		string text3 = "";
		if (!string.IsNullOrEmpty(this.shopcartID))
		{
			DataTable dataTable = BLLInstance.BllShoppingCarts.GetList(" CartID in (" + this.shopcartID + ")").Tables[0];
			for (int i = 0; i < dataTable.Rows.Count; i++)
			{
				DataRow dataRow = dataTable.Rows[i];
				text = text + dataRow["productID"].ToString() + ",";
				text2 = text2 + dataRow["buyproductNum"].ToString() + ",";
				text3 = text3 + dataRow["productPrice"].ToString() + ",";
			}
			if (!string.IsNullOrEmpty(text))
			{
				text = text.Substring(0, text.Length - 1);
				text2 = text2.Substring(0, text2.Length - 1);
				text3 = text3.Substring(0, text3.Length - 1);
			}
			string[] productIDS = text.Split(new char[]
			{
				','
			});
			string[] productNum = text2.Split(new char[]
			{
				','
			});
			string[] productPrice = text3.Split(new char[]
			{
				','
			});
			DataTable table = this.creatOrder.CreatOrderByDeliverType(productIDS, productNum, base.user.UserID, productPrice);
			dataSet = new DataSet();
			dataSet.Tables.Add(table);
		}
		return dataSet;
	}
	private bool checkInput()
	{
		int num = 0;
		num = this.Repeater1.Items.Count;
		bool result = true;
		for (int i = 0; i < num; i++)
		{
			UserControl userControl = (UserControl)this.Repeater1.Items[i].FindControl("shopcart");
			RadioButtonList radioButtonList = new RadioButtonList();
			try
			{
				radioButtonList = (RadioButtonList)userControl.FindControl("deliverType");
				if (radioButtonList != null)
				{
					bool flag = false;
					for (int j = 0; j < radioButtonList.Items.Count; j++)
					{
						if (radioButtonList.Items[j].Selected)
						{
							flag = true;
						}
					}
					if (radioButtonList.Items.Count > 0)
					{
						if (!flag)
						{
							result = false;
						}
					}
				}
			}
			catch
			{
			}
			RadioButtonList radioButtonList2 = (RadioButtonList)userControl.FindControl("address_list");
			if (radioButtonList2.SelectedIndex == -1)
			{
				result = false;
			}
		}
		return result;
	}
	protected void btn_next_Click(object sender, EventArgs e)
	{
		if (!this.checkInput())
		{
			this.WriteErrMsg("", "请认真填写各项信息", "");
		}
		int num = 0;
		num = this.Repeater1.Items.Count;
		string text = "";
		string text2 = "";
		string text3 = "";
		string text4 = "";
		string text5 = "";
		string text6 = "";
		string text7 = "";
		for (int i = 0; i < num; i++)
		{
			UserControl userControl = (UserControl)this.Repeater1.Items[i].FindControl("shopcart");
			RadioButtonList radioButtonList = (RadioButtonList)userControl.FindControl("paytype");
			RadioButtonList radioButtonList2 = new RadioButtonList();
			try
			{
				radioButtonList2 = (RadioButtonList)userControl.FindControl("deliverType");
			}
			catch
			{
			}
			RadioButtonList radioButtonList3 = (RadioButtonList)userControl.FindControl("address_list");
			HiddenField hiddenField = (HiddenField)this.Repeater1.Items[i].FindControl("HiddenField1");
			if (radioButtonList2 != null)
			{
				int num2 = 0;
				string text8 = "";
				for (int j = 0; j < radioButtonList2.Items.Count; j++)
				{
					if (radioButtonList2.Items[j].Selected)
					{
						text8 = radioButtonList2.SelectedValue;
						break;
					}
				}
				if (!string.IsNullOrEmpty(text8))
				{
					string[] contentArray = text8.ToString().Split(new char[]
					{
						'$'
					});
					string deliverChargeContentDetailByName = Shop_DeliverType.GetDeliverChargeContentDetailByName("deliverTypeID", contentArray);
					if (!string.IsNullOrEmpty(deliverChargeContentDetailByName))
					{
						num2 = deliverChargeContentDetailByName.ToInt32(new int[0]);
					}
				}
				text = text + num2.ToString() + ",";
				text2 = text2 + text8 + "|";
			}
			else
			{
				text += "0,";
				text2 += "null|";
			}
			text3 = text3 + radioButtonList3.SelectedValue + ",";
			text4 = text4 + hiddenField.Value + ",";
			UserControl userControl2 = (UserControl)this.Repeater1.Items[i].FindControl("ProductGV1");
			HiddenField hiddenField2 = (HiddenField)userControl2.FindControl("hd_productIDS");
			HiddenField hiddenField3 = (HiddenField)userControl2.FindControl("hd_productNum");
			HiddenField hiddenField4 = (HiddenField)userControl2.FindControl("hd_productPrice");
			text5 = text5 + hiddenField2.Value + "|";
			text6 = text6 + hiddenField3.Value + "|";
			text7 = text7 + hiddenField4.Value + "|";
		}
		text = text.Substring(0, text.Length - 1);
		text2 = text2.Substring(0, text2.Length - 1);
		text3 = text3.Substring(0, text3.Length - 1);
		text4 = text4.Substring(0, text4.Length - 1);
		this.Session["DeliverCharge"] = text2;
		base.Response.Redirect(string.Format("ShopCartOrderSumbit.aspx?shopID={0}&&deliverType={1}&&address={2}&&productID={3}&&productNum={4}&&productPrice={5}&&shopcartID={6}", new object[]
		{
			text4,
			text,
			text3,
			text5,
			text6,
			text7,
			this.shopcartID
		}));
	}
	protected void btn_back_Click(object sender, EventArgs e)
	{
		try
		{
			base.Response.Redirect("ShoppingCart.aspx");
		}
		catch
		{
			base.Response.Redirect("ShoppingCart.aspx");
		}
	}
}
